<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

// autor/i etapy: 
// 10.12.2013

class Udalost extends CI_Controller {
	
	public function index() {
		redirect('main');
	}
	
	public function zobraz($id, $start = null) {
		//$id = id v tabulke casy_udalosti 
		//$start = cas kedy kurz zacne v minutach (len pre plavajuci termin)		
		if ($start == null) {
			$data['dump'] = "id = $id";//string obsahujuci html pre main content
      
			$this->load->model('model_rozvrh');
			$id_ud = $this->model_rozvrh->get_id_udalosti($id);
			$udalost = $this->model_rozvrh->get_info_udalosti($id_ud);
			$this->load->model('model_user');
			$cas_udalosti = $this->model_user->get_cas_udalosti($id);
			$kolektivy = $this->model_user->get_kolektivy();
		
      $trvanie = $this->model_user->get_trvanie($id);
      $zaplnenie =  $this->model_user->get_zaplnenie($id);
      $kapacita =  $this->model_user->get_maxLudi($id_ud['id']);
      $cas = $this->model_user->get_cas_od($id);
  	
      
			$megadata = array(
				'data' => $data,
				'udalost' => $udalost,
				'kolektivy' => $kolektivy,
				'cas' => $cas,
        'trvanie' => $trvanie,
        'zaplnenie' => $zaplnenie,
        'kapacita' => $kapacita,
				//'id_ud' => $id_ud
        'id_casu_ud' =>$id,
		'cas_udalosti' => $cas_udalosti
			);
 
			if ($this->session->userdata('is_logged_in')){
		    if ($this->session->userdata('admin'))
		        $this->template->make_template($megadata, 'admin_rozvrh_udalost');
        else
            $this->template->make_template($megadata, 'user_rozvrh_udalost');
      }else
         $this->template->make_template($megadata, 'rozvrh_udalost');
		} else {
			$this->load->model('model_rozvrh');
			$data['dump'] = "id = $id, cas  =". $this->model_rozvrh->MinsToStr($start);
			$cas = $this->model_rozvrh->MinsToStr($start);  //spravi z poctu minut string v tvare hh:mm:00
      $id_ud = $this->model_rozvrh->get_id_udalosti($id);
      $udalost = $this->model_rozvrh->get_info_udalosti($id_ud);
	  $this->load->model('model_user');
	  $cas_udalosti = $this->model_user->get_cas_udalosti($id);
      $kolektivy = $this->model_user->get_kolektivy(); 
	    $trvanie = $this->model_user->get_trvanie($id);
      $zaplnenie =  $this->model_user->get_zaplnenie($id);
      $kapacita =  $this->model_user->get_maxLudi($id_ud['id']);
      $megadata = array(
          'data' => $data,
          'udalost' => $udalost,
		  'kolektivy' => $kolektivy,
		  'cas' => $cas,
      'trvanie' => $trvanie,
          'id_ud' => $id_ud,
          'zaplnenie' => $zaplnenie,
          'kapacita' => $kapacita,
          'id_casu_ud' =>$id,
		  'cas_udalosti' => $cas_udalosti
   
      );
			if ($this->session->userdata('is_logged_in')){
		    if ($this->session->userdata('admin'))
		        $this->template->make_template($megadata, 'admin_rozvrh_udalost');
        else
            $this->template->make_template($megadata, 'user_rozvrh_udalost');
      }else
        $this->template->make_template($megadata, 'rozvrh_udalost');
		}
	}
}
